<?php
/**
 * Instalacja obslugiwanych domen
 * Możliwość wskazania kilka domen na jedną
 * 
 */
	if(isset($_SERVER['HTTP_HOST'])) {
		$d__ = preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']);
	}else{
		$d__ = 'web.maxgreetings';
	}
	
	if (!defined('HOST')) {

//		// uruchomienie bazy konfiguracyjnej z listą domen
//		try {
//			$db = new PDO('sqlite:../database/setup.db',null,null,array(PDO::ATTR_PERSISTENT => ''));
//			$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//			$connected = is_object($db);
//		}
//		catch(PDOException $e) {
//			die('Error connecting to database.: '.$e->getMessage());
//		}
		
		
		$map = array(
			'max.21w.pl'	=>	array('name'=>'web.maxgreetings','status'=>'active','lang'=>'eng'),
			'maxgreetings.hdphd.com' =>	array('name'=>'web.maxgreetings','status'=>'active','lang'=>'eng'),
			// localhost			
			'web.max'	=> array('name'=>'web.maxgreetings','status'=>'active','lang'=>'eng')
		);		
		
		if (array_key_exists($d__,$map)) {			
		    define('HOST',$map[$d__]['name']);
		    Configure::write('Config.host', $map[$d__]['name']);
		    Configure::write('Config.status', $map[$d__]['status']);		    
		}else{
			define('HOST', 'web.maxgreetings');
		    Configure::write('Config.host', 'web.maxgreetings');
		    Configure::write('Config.status', 'active');
		    $d__ = 'web.maxgreetings';
		}
	}
	
	/**
	 * definicja sciezki do zapisywania plikow 
	 * dla modelu upload
	 */
	if (!defined('UPLOAD_PATH')) {
	    define('UPLOAD_PATH', 'files/'.HOST.'/upload');
	}	
	
	
/**
 * Instalacja wersji językowej
 * @var unknown_type
 */	
    $languages = array(
    	 'pol'=>array('name'=>__("Polih",true))
    	,'eng'=>array('name'=>__("Angielski",true))
    );
	
	
	// zainstalowane jezyki
	Configure::write('Config.languages', $languages);	

	Configure::write('Config.default_lang', $map[$d__]['lang']);
	
/**
 * Definicja grup uzytkowników
 */
	$users_groups = array(
		'admin'=>array('name'=>__("Admin",true))
		,'manag'=>array('name'=>__("Manag",true))		
		,'emplo'=>array('name'=>__("Employee",true))		
		,'provi'=>array('name'=>__("Provider",true))
		,'users'=>array('name'=>__("User",true))
		,'compa'=>array('name'=>__("Company",true))
	);
	Configure::write('Config.users_groups', $users_groups);
	
/**
 * Google
 */

	Configure::write('Config.google.path',"files/".HOST."/google/");
	if(isset($_SERVER['HTTP_HOST']))Configure::write('Config.google.apikey',"apikey.".preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']).".txt");
	if(isset($_SERVER['HTTP_HOST']))Configure::write('Config.google.analytics',"analytics.".preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']).".txt");

	
/**
 * Newsletter
 */
$subject = Configure::read('Newsletter.unsubscribe_subject');
$subject = Configure::read('Newsletter.subscribe_subject');
$from = Configure::read('Newsletter.from'); #Required
$from_email = Configure::read('Newsletter.from_email'); #Required

$subject = Configure::read('Newsletter.sendX'); #Number of emails to sent at each admin_send call.
$subject = Configure::read('Newsletter.sendInterval'); #the interval time before send next batch
$subject = Configure::read('Newsletter.mail_opt_out_message');
$subject = Configure::read('Newsletter.emptyImagePath');

// domye daty dla cen
Configure::write('default_prices_dates',array(
	0=>array('f'=>date('Y').'-01-01','t'=>date('Y').'-03-31'),
	1=>array('f'=>date('Y').'-04-01','t'=>date('Y').'-06-30'),
	2=>array('f'=>date('Y').'-07-01','t'=>date('Y').'-07-31'),
	3=>array('f'=>date('Y').'-08-01','t'=>date('Y').'-09-30'),
	4=>array('f'=>date('Y').'-10-01','t'=>date('Y').'-12-31'),
	5=>array('f'=>(date('Y')+1).'-01-01','t'=>(date('Y')+1).'-03-31'),
	6=>array('f'=>(date('Y')+1).'-04-01','t'=>(date('Y')+1).'-06-30'),
	7=>array('f'=>(date('Y')+1).'-07-01','t'=>(date('Y')+1).'-07-31'),
	8=>array('f'=>(date('Y')+1).'-08-01','t'=>(date('Y')+1).'-09-30'),
	9=>array('f'=>(date('Y')+1).'-10-01','t'=>(date('Y')+1).'-12-31')
));
	
	/**
	 * uniqiname for uploaded file
	 * @param $fileName
	 */
	function uniqid_file_name($fileName){
		preg_match("/\.([^\.]+)$/", $fileName, $matches);
		return uniqid('file_').'.'.strtolower($matches[1]);
	}